
import mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;

import java.io.IOException;
import java.io.InputStream;


public class Mybastis06 {
    public static void main(String[] args) throws IOException {
        User user = new User();
        user.setId(3);
        user.setUsername("changbe");
        user.setFullname("刘长柏");
        user.setPassword("4444444");
        user.setAddress("山东省聊城市XXX小区");


//        操作Mybastis的四个步骤
//        1.加载配置文件

        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//        2.创建SqlSe
        SqlSession sqlSession = sqlSessionFactory.openSession();
//        3.执行sql
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        userMapper.updateOne(user);
        sqlSession.commit();//插入，修改、删除，都需要提交事务
//        4.关闭Sess
        sqlSession.close();
    }
}
